const { defineConfig } = require("@vue/cli-service");
const path = require('path');

//通过全局对象process.evn来获取

console.log(process.env)

function resolve(dir) {
  console.log(path.resolve(dir))
  return path.resolve(dir)
}
module.exports = defineConfig({
  //构建项目一定要加这个属性,不然资源全部会挂掉
  publicPath: ".",
  transpileDependencies: true,
  lintOnSave: false,
  //开发服务器配置,配置完一定要重启项目! 配置完一定要重启项目! 配置完一定要重启项目!
  devServer: {
    //配置启动服务器的端口号
    port: parseInt(process.env.VUE_APP_PORT),
    //配置地理
    proxy: {
      "/api": {
        //目标服务器
        target: process.env.VUE_APP_BASE_URL,
        //路径重写
        pathRewrite: {
          "^/api": ""
        }
      }
    }
  },
  chainWebpack: (config) => {
    //别名配置
    config.resolve.alias
      .set('&', resolve('src'))
      .set('assets', resolve('src/assets'))
      .set('components', resolve('src/components'))
      .set('layout', resolve('src/layout'))
      .set('base', resolve('src/base'))
      .set('static', resolve('src/static')) 

      //打包配置hash文件名 一般是使用版本号+时间戳
    config.output
      .filename(
        `assets/js/[name].${process.env.VUE_APP_VERSION}.${+new Date()}.js`
      )
      .chunkFilename(
        `assets/js/[name].${process.env.VUE_APP_VERSION}.${+new Date()}.js`
      )
      .end();
  }

});
//真实的请求地址:
//'http://chst.vip/data/index.json'

//代理会解析成

//'http://chst.vip/data/index.json'
